** import compensation analysis data
use "~/Dropbox/revolving_door_jmp/replication_files/earning_df_jop.dta", clear

** export result directory

global reg_rd  "~/Dropbox/revolving_door_jmp/result"

** log transformation of DV
g salary_l = log(salary+1) 
g stock_l = log(stock_value+1)

** log transformation of controls

g asset_l = log(TotalAsset+1)
g liability_l = log(TotalLiab+1)

** encode categorical variables for regressions

encode stkcd, g(stkcd_1)
drop stkcd
rename stkcd_1 stkcd

encode sectorid, g(sectorid_1)
drop sectorid
rename sectorid_1 sectorid

** label variables
lab var subsidy_period_dummy "Previous Subsidy"
label var salary_l "Salary"
label var stock_l "Stock"
global ind_controls  age education  female  bord_mbr 
global firm_controls asset_l liability_l

* regression setting
global reg_setting_h3  lab dec(3) noas nocons drop( $ind_controls $firm_controls) 


**# Table A.20: Compensation Analysis Using Different Time Interval
lab var subsidy_l1_dummy "Previous Subsidy (1yr window)"
lab var subsidy_l2_dummy "Previous Subsidy (2yrs window)"


reghdfe salary_l subsidy_l1_dummy  $firm_controls $ind_controls  , absorb(stkcd entr_yr i.stkcd#c.year)  vce(cluster stkcd) 
outreg2 using "$reg_rd/h3_alter_t.tex", replace $reg_setting_h3  ///
addtext("Firm and Entry Year FE", "Y", "Firm Controls", "Y", "Individual Controls", "Y", "Firm-specific Trend", "Y" ) 

reghdfe salary_l subsidy_l2_dummy  $firm_controls $ind_controls  , absorb(stkcd entr_yr i.stkcd#c.year)  vce(cluster stkcd) 
outreg2 using "$reg_rd/h3_alter_t.tex", append $reg_setting_h3  ///
addtext("Firm and Entry Year FE", "Y", "Firm Controls", "Y", "Individual Controls", "Y", "Firm-specific Trend", "Y" ) 

reghdfe stock_l subsidy_l1_dummy  $firm_controls $ind_controls  , absorb(stkcd entr_yr i.stkcd#c.year)  vce(cluster stkcd) 
outreg2 using "$reg_rd/h3_alter_t.tex", append $reg_setting_h3  ///
addtext("Firm and Entry Year FE", "Y", "Firm Controls", "Y", "Individual Controls", "Y", "Firm-specific Trend", "Y" ) 

reghdfe stock_l subsidy_l2_dummy  $firm_controls $ind_controls  , absorb(stkcd entr_yr i.stkcd#c.year)  vce(cluster stkcd) 
outreg2 using "$reg_rd/h3_alter_t.tex", append $reg_setting_h3  ///
addtext("Firm and Entry Year FE", "Y", "Firm Controls", "Y", "Individual Controls", "Y", "Firm-specific Trend", "Y" ) 


**# Table A.21: Effect Hetergenoeity Across Different Levels of Government

reghdfe salary_l subsidy_period_dummy  $firm_controls $ind_controls if level ==2 , absorb(stkcd entr_yr i.stkcd#c.year)  vce(cluster stkcd) 
outreg2 using "$reg_rd/h3_het.tex", replace $reg_setting_h3  ///
addtext("Firm and Entry Year FE", "Y", "Firm Controls", "Y", "Individual Controls", "Y", "Firm-specific Trend", "Y" ) cttop("Province")

reghdfe salary_l subsidy_period_dummy  $firm_controls $ind_controls if level ==4 , absorb(stkcd entr_yr i.stkcd#c.year)  vce(cluster stkcd) 
outreg2 using "$reg_rd/h3_het.tex", append $reg_setting_h3  ///
addtext("Firm and Entry Year FE", "Y", "Firm Controls", "Y", "Individual Controls", "Y", "Firm-specific Trend", "Y" ) cttop("Prefecture")


reghdfe salary_l subsidy_period_dummy  $firm_controls $ind_controls if level ==3 , absorb(stkcd entr_yr i.stkcd#c.year)  vce(cluster stkcd) 
outreg2 using "$reg_rd/h3_het.tex", append $reg_setting_h3  ///
addtext("Firm and Entry Year FE", "Y", "Firm Controls", "Y", "Individual Controls", "Y", "Firm-specific Trend", "Y" ) cttop("County")

reghdfe stock_l subsidy_period_dummy  $firm_controls $ind_controls if level ==2 , absorb(stkcd entr_yr i.stkcd#c.year)  vce(cluster stkcd) 
outreg2 using "$reg_rd/h3_het.tex", append $reg_setting_h3  ///
addtext("Firm and Entry Year FE", "Y", "Firm Controls", "Y", "Individual Controls", "Y", "Firm-specific Trend", "Y" )  cttop("Province")


reghdfe stock_l subsidy_period_dummy  $firm_controls $ind_controls if level ==4 , absorb(stkcd entr_yr i.sectorid#c.year)  vce(cluster stkcd) 
outreg2 using "$reg_rd/h3_het.tex", append $reg_setting_h3  ///
addtext("Firm and Entry Year FE", "Y", "Firm Controls", "Y", "Individual Controls", "Y", "Firm-specific Trend", "Y" ) cttop("Prefecture")


reghdfe stock_l subsidy_period_dummy  $firm_controls $ind_controls if level ==3 , absorb(stkcd entr_yr i.sectorid#c.year)  vce(cluster stkcd) 
outreg2 using "$reg_rd/h3_het.tex", append $reg_setting_h3  ///
addtext("Firm and Entry Year FE", "Y", "Firm Controls", "Y", "Individual Controls", "Y", "Firm-specific Trend", "Y" ) cttop("County")

**# Table A.22: Compensation Analysis at the Individual-Firm Level

use "~/Dropbox/revolving_door_jmp/replication_files/earning_col_jop.dta", clear

** export result directory

global reg_rd  "~/Dropbox/revolving_door_jmp/result"

** log transformation of DV
g salary_l = log(salary+1) 
g stock_l = log(stock_value+1)

** log transformation of controls

g asset_l = log(TotalAsset+1)
g liability_l = log(TotalLiab+1)

** encode categorical variables for regressions

encode stkcd, g(stkcd_1)
drop stkcd
rename stkcd_1 stkcd


** label variables
lab var subsidy_period_dummy "Previous Subsidy"
label var salary_l "Salary"
label var stock_l "Stock"
global ind_controls  age education  female  bord_mbr 
global firm_controls asset_l liability_l


global reg_setting_h3  lab dec(3)   noas nocons  keep(subsidy_period_dummy) ///noas

reghdfe salary_l subsidy_period_dummy  , absorb(stkcd entr_yr )  vce(cluster stkcd) 
outreg2 using "$reg_rd/h3_ind.tex", replace  $reg_setting_h3 ///
addtext("Firm and Entry Year FE", "Y") 

reghdfe salary_l subsidy_period_dummy $ind_controls  , absorb(stkcd entr_yr )  vce(cluster stkcd) 
outreg2 using "$reg_rd/h3_ind.tex", append $reg_setting_h3 ///
addtext("Firm and Entry Year FE", "Y", "Individual Controls", "Y") 

reghdfe salary_l subsidy_period_dummy   $firm_controls $ind_controls , absorb(stkcd entr_yr )  vce(cluster stkcd) 
outreg2 using "$reg_rd/h3_ind.tex", append  $reg_setting_h3  ///
addtext("Firm and Entry Year FE", "Y", "Firm Controls", "Y", "Individual Controls", "Y" ) 


reghdfe stock_l subsidy_period_dummy  , absorb(stkcd entr_yr )  vce(cluster stkcd) 
outreg2 using "$reg_rd/h3_ind.tex", append  $reg_setting_h3 ///
addtext("Firm and Entry Year FE", "Y") 

reghdfe stock_l subsidy_period_dummy $firm_controls  , absorb(stkcd entr_yr )  vce(cluster stkcd) 
outreg2 using "$reg_rd/h3_ind.tex", append $reg_setting_h3 ///
addtext("Firm and Entry Year FE", "Y", "Individual Controls", "Y" ) 


reghdfe stock_l subsidy_period_dummy   $firm_controls $ind_controls , absorb(stkcd entr_yr )  vce(cluster stkcd) 
outreg2 using "$reg_rd/h3_ind.tex", append  $reg_setting_h3  ///
addtext("Firm and Entry Year FE", "Y", "Firm Controls", "Y", "Individual Controls", "Y") 

